/*
----------------------------------------------------------------------------------------------------
This source file is part of the Gamut Framework
Copyright (c) 2007 by Ryan Holcombe

This program is free software; you can redistribute it and/or modify it under the terms of the GNU
Lesser General Public License as published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
----------------------------------------------------------------------------------------------------
*/


#ifndef _Exception_h_
#define _Exception_h_

#include <exception>
#include <string>

#define EXCEPTION_TO_LOG
#define EXCEPTION_TO_STDERR

namespace Gamut
{
    /** When thrown, provides information about an error that has occurred inside the framework.
		\remarks
			Exceptions will log if EXCEPTION_TO_LOG is defined\n
			Exceptions will be send to the console if EXCEPTION_TO_STDERR is defined
    */

	class Exception : public std::exception
    {
    protected:
		int mLine;
		std::string mMsg;
		std::string mFunction;
		mutable std::string mFullError;
    public:

		/** Default constructor
		*/
		Exception(const std::string& function, const std::string& msg);


		/** Constructor which includes variables in the exception
		*/
		Exception(const std::string& function, const char* msg, ...);


		/** Needed for compatibility with std::exception
 		*/
		~Exception() throw() {}


		/** Displays the full error, includes source, line number, and description
		*/
		virtual const std::string& getFullError(void) const { return mFullError; }


		/** Displays the error text
		*/
		virtual const std::string& getMsg(void) const { return mMsg; }


		/** Gets source file name.
		*/
		virtual const std::string& getFunction() const { return mFunction; }


		/** Gets line number.
		*/
		virtual const int& getLine() const { return mLine; }


		/** Override std::exception::what
		*/
		const char* what() const throw() { return getFullError().c_str(); }
    };
}
#endif
